package com.chen.facemanager.redis;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @ClassName RedisConfig
 * @Description
 * @Author Mr-CHEN
 * @Date 2019/8/20 20:01
 * @Version V1.0
 **/

@Configuration
@EnableAutoConfiguration
//@PropertySource("classpath:redis.properties")
public class RedisConfig {

    @Value("${redis.host}")
    private  String host;

    @Value("${redis.port}")
    private  int port;

    @Value("${redis.password}")
    private  String passwd;

    @Value("${redis.timeout}")
    private  int timeout;

    @Value("${redis.blockWhenExhausted}")
    private  boolean blockWhenExhausted;

    @Value("${redis.maxIdle}")
    private  int maxIdle;

    @Value("${redis.maxWaitMillis}")
    private  int maxWaitMillis;

    @Value("${redis.maxTotal}")
    private  int maxTotal;

    @Value("${redis.testOnBorrow}")
    private  boolean testOnBorrow;


    private JedisPool jedisPool;

    @Bean
    public JedisPoolConfig getRedisConfig() {
        JedisPoolConfig config=new JedisPoolConfig();
        return config;
    }

    @Bean
    public JedisPool getJedisPool() {
        JedisPoolConfig config=getRedisConfig();
        config.setMaxIdle(maxIdle);
        config.setMaxTotal(maxTotal);
        config.setBlockWhenExhausted(blockWhenExhausted);
        config.setTestOnBorrow(testOnBorrow);
        config.setMaxWaitMillis(maxWaitMillis);
//        JedisPool jedisPool=new JedisPool(config,host,port,timeout,passwd);
        JedisPool jedisPool=new JedisPool(config,host,port,timeout);
        return jedisPool;
    }

}